define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fruitwarrioruser/index',
                    add_url: 'fruitwarrioruser/add',
                    edit_url: 'fruitwarrioruser/edit',
                    del_url: 'fruitwarrioruser/del',
                    multi_url: 'fruitwarrioruser/multi',
                    table: 'fruit_warrior_user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'openid', title: __('Openid')},
                        {field: 'token', title: __('Token')},
                        {field: 'session', title: __('Session')},
                        {field: 'nick_name', title: __('Nick_name')},
                        {field: 'avatar_url', title: __('Avatar_url'), formatter: Table.api.formatter.url},
                        {field: 'level', title: __('Level')},
                        {field: 'coin', title: __('Coin')},
                        {field: 'diamond', title: __('Diamond')},
                        {field: 'weapon_v2', title: __('Weapon_v2')},
                        {field: 'sign_in_num', title: __('Sign_in_num')},
                        {field: 'is_sign_in', title: __('Is_sign_in')},
                        {field: 'last_sign_in', title: __('Last_sign_in')},
                        {field: 'enter_xcx_award', title: __('Enter_xcx_award')},
                        {field: 'invite_award', title: __('Invite_award')},
                        {field: 'week_lucky', title: __('Week_lucky')},
                        {field: 'last_logout_time', title: __('Last_logout_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'endless_ticket_num', title: __('Endless_ticket_num')},
                        {field: 'endless_score', title: __('Endless_score')},
                        {field: 'phone_number', title: __('Phone_number')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});